import store from '@/store'

/**
 * 获取字典值的显示名
 * @param {(string)} dictCode
 * @param {(string)} dictItemValue
 * @returns {string}
 */
export function dictItemLabel(dictItemValue, dictCode) {
	if (arguments.length < 2) {
		return dictItemValue
	}
	if (!dictItemValue) { return dictItemValue; }

	var dicts = store.getters.dicts;
	var dict = dicts.find(n => n.code === dictCode);
	if (dict && dict.items && dict.items.length > 0) {
		var dictItem = dict.items.find(n => n.value === dictItemValue.toString());
		if (dictItem) {
			return `${dictItem.label}(${dictItem.value})`;
		}
	}

	return dictItemValue
}

export function enumLabel(value, enumList) {
	if (arguments.length < 2) {
		return value
	}
	var _enum = enumList.find(n => n.value === value);
	if (_enum) {
		return `${_enum.label}`;
	}

	return value
}
